import http from "../index";
import qs from "qs"; //引入node自带的qs模块
//请求精品数据
export const JingPinAPI = (): RES<IProduct> => http.get("/products/recommend");

//请求热门数据
export const RenMenAPI = (): RES<IProduct> => http.get("/products/hot");

//商品信息和搜索
export const GoodsSearchAPI = (params: IGoodsParams): RES<IGoodsList[]> =>
  http.get("/products", { params });

//商品详情
export const GoodsAPI = (id: number): RES<IDetails> =>
  http.get(`/products/${id}`);

//获取验证码
export const SendPhoneAPI = (params: ISendPhoneParams): REF =>
  http.post("/sendSMS", qs.stringify(params));

//验证码登录请求,并注册手机号
export const PhoneLogin = (params: IPhoneLoginParams): REF =>
  http.post("/phoneRegin", qs.stringify(params));

// 微信登录请求
export const WeiXinLogin = (params: IWeiXinLoginParams): REF =>
  http.post("/wechatUsers/PCLogin", qs.stringify(params));

//手机号绑定微信
export const bindingAPI = (params: IBindingParams): REF =>
  http.post("/wechatUsers/binding", qs.stringify(params));

// 用户信息
export const UserAPI = (): RES<IUseInfo> => http.get("/shop/userProfiles");

//查看购物车
export const ShowCartAPI = (): REC => http.get("/shop/carts");

//删除购物车
export const CartsDelAPI = (params: any): REF =>
  http.delete(`/shop/carts?productIds=${params.id}`);

//加入购物车
export const CartsAddPI = (params: IAddCartParams): RES<IAddCart> =>
  http.post("/shop/carts/add", qs.stringify(params));
